# --*-- coding:utf-8 --*--
import re

from pymysql import connect


def Link_database():
    """链接数据库"""
    # con = connect(host='rm-m5ev2j6ywo4m51ebu5o.mysql.rds.aliyuncs.com', user='root', passwd='112358Ys', db='djt',
    #               charset='utf8')
    con = connect(host='193.112.133.62', user='ydsp', password='ydsp123456', db='djt', charset='utf8')
    # con = connect(host='193.112.133.62', user='admin', password='admin888', db='admin', charset='utf8')

    obj = con.cursor()  # 游标对象
    return con, obj


def a():
    con, obj = Link_database()

    # sql = """select c.*,d.* from expand_repeat as d left join (select a.*, b.zd_nickname,b.zd_passwd,b.pay_date,b.is_diagnosis,b.landing_times from user_expand as b right join (select id,username,first_name,taobao_account_name,last_login_time,date_joined,vip_date,vip_level,user_qq,user_wx from auth_user left join taobao_account on auth_user.id=taobao_account.user_id where auth_user.username='{}') as a on b.user_name=a.username) as c on c.username=d.user_name""".format(
    #     "test2")
    sql = """select * from auth_user where first_name='15926211153'"""
    # sql = """delete from auth_user where id=939"""
    obj.execute(sql)
    q = obj.fetchall()
    con.commit()

    return q


def b():
    con, obj = Link_database()

    sql = """select a.*, b.zd_nickname,b.zd_passwd,b.pay_date,b.is_diagnosis,b.landing_times from user_expand as b right join (select id,username,first_name,taobao_account_name,last_login_time,date_joined,vip_date,vip_level,user_qq,user_wx from auth_user left join taobao_account on auth_user.id=taobao_account.user_id where auth_user.username='{}') as a on b.user_name=a.username""".format(
        "test2")

    obj.execute(sql)
    q = obj.fetchall()

    return q


def sum(s):
    if not s:
        return 0

    l1 = list(s)
    l1_list = []

    z = []
    for e in l1:
        if l1.count(e) > 1:
            z.append(e)

    if not z:
        return len(s)

    for i in l1:
        m = []
        for q in l1:
            if i == q:
                j = l1.index(i)
                m.append(j)
                l1[j] = ''
        print(l1)
        m.append(len(l1))
        m.reverse()
        r = []
        for y in range(len(m) - 1):
            r.append(m[y] - m[y + 1])

        r.sort(reverse=True)
        if r:
            l1_list.append(r[0])

    l1_list.sort(reverse=True)

    return l1_list[0]


if __name__ == '__main__':
    pass
    c = 'kkaw'
    # print(c.count('1'))
    # print(sum(c))
    print(a())

